<template>
	<view class="set">
		<comHead :title="'聊天管理'" :isLeft="true" :isRight="false"></comHead>
		
		<view class="content">
			<view class="top">
				<view class="item" v-for="item,index in qunUser" :key="index">
					<image :src="getImg(item.avatar)" mode="aspectFill"></image>
					<text>{{item.name || item.nickname}}</text>
				</view>
				<template v-if="isQun==2">
					<view class="item add" @click="comLink('/pages/social/changeQunUser?id='+id+'&type=1')">
						<image src="../../static/social/add.png" mode="aspectFill"></image>
					</view>
					<view class="item dec" @click="comLink('/pages/social/changeQunUser?id='+id+'&type=2')">
						<image src="../../static/social/dec.png" mode="aspectFill"></image>
					</view>
				</template>
				<template v-else>
					<view class="item add" @click="comLink('/pages/social/sponsor?id='+id)">
						<image src="../../static/social/add.png" mode="aspectFill"></image>
					</view>
				</template>
			</view>
			
			<view class="list" v-if="isQun==2">
				<view class="list-item">
					<text class="l">群号</text>
					<view class="r">
						<text>{{qunDetail.group_no}}</text>
						<image src="http://47.116.126.182:2003/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="list-item" @click="qunDetail.user_type!=1?comLink('/pages/social/editName?id='+id):''">
					<text class="l">群聊名称</text>
					<view class="r">
						<text>{{qunDetail.name}}</text>
						<image src="http://47.116.126.182:2003/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="list-item" @click="qunDetail.user_type!=1?comLink('/pages/social/editNotify?id='+id):''">
					<text class="l">群公告</text>
					<view class="r">
						<text class="gg">{{qunDetail.notice}}</text>
						<image src="http://47.116.126.182:2003/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="list-item" v-if="isQun==2 && qunDetail.user_type==2"  @click="comLink('/pages/social/admin?id='+id)">
					<text class="l">群管理</text>
					<view class="r">
						<image src="http://47.116.126.182:2003/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
			
			<view class="list">
				<view class="list-item"  @click="comLink('/pages/social/findChatInfo?id='+id+'&isQun='+isQun)">
					<text class="l">聊天记录</text>
					<view class="r">
						<image src="https://siha.vxmeng.com/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="list-item">
					<text class="l">置顶聊天</text>
					<view class="r">
						<switch :checked="qunDetail.top==1?false:true" color=" #0f9dfe" @change="doAddTopQun"/>
					</view>
				</view>
			</view>
			
			<view class="list" @click="delJl">
				<view class="list-item">
					<text class="l">清空聊天记录</text>
					<view class="r">
						<image src="https://siha.vxmeng.com/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
			
			<view class="list del">
				<view class="list-item" @click="onDel">
					<text class="l">{{isQun==2?'退出群聊':'删除好友'}}</text>
				</view>
			</view>
		</view>
		
		<view class="pop" v-if="isDel" @click.stop="">
			<view class="content-box">
				<view class="t" v-if="isQun==2">
					即将退出群聊 “{{qunDetail.name}}”
				</view>
				<view class="t" v-else>
					确认删除好友么？
				</view>
<!-- 				<view class="c">
					<radio :value="'1'" :checked="agree === '1'" @click="radioChange"/>
					清空聊天记录
				</view> -->
				<view class="b">
					<view class="btn" @click="isDel=false">
						<text>取消</text>
					</view>
					<view class="btn" @click="exitQun">
						<text>确认</text>
					</view>
				</view>
			</view>
		</view>
		<comPop @hidePop="popObj.isPop=false" :type="popObj.type" :title="popObj.title" @sendPopFun="sendPopFun"
				:isInput="popObj.isInput" v-if="popObj.isPop"></comPop>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				qunDetail:{},
				qunUser:[],
				isQun: 1,
				isAdmin: true,
				isDel: false,
				zdVal: false,
				popObj: {
					title: "",
					isPop: false,
					isInput: false
				},
			}
		},
		onLoad(options) {
			this.isQun = options.isQun
			this.id = options.id
		},
		onShow() {
			this.getQunDetail()
			if(this.isQun==2){
				this.getQunUser()
			}else{
				this.getFriendDetail()
			}
		},
		methods: {			
			async exitQun(){
				let url = "api/lt/doDelUserFriend"
				let objData = {
						friend_id: this.id
					}
				if(this.isQun==2){
					url = "api/qun/doDelQunUserOne"
					objData = {
						group_no:this.qunDetail.group_no
					}
				}
				const res = await this.$myRequest({
					url: url,
					data: objData
				})
				if (res.code == 1) {
					console.log(res)
					this.$tools.showTx(res.msg)
					setTimeout(()=>{
						this.$tools.toTabs('/pages/contact/contact')
					},1000)
				}
			},
			async getFriendDetail() {
				this.qunUser = []
				const res = await this.$myRequest({
					url: 'api/lt/getFriendDetail',
					data: {
						friend_id: this.id,
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.qunUser.push(res.data)
				}
			},
			
			async doAddTopQun(e) {
				let eVal = e.detail.value
				let url = "api/lt/doTopUserFriend"
				let objData = {
					friend_id: this.id,
					top:eVal?2:1
				}
				if (this.isQun==2) {
					url = "api/qun/doAddTopQun"
					objData = {
						qun_id: this.id,
						top:eVal?2:1
					}
				}
				const res = await this.$myRequest({
					url: url,
					data: objData
				})
				if (res.code == 1) {
					console.log(res)
					this.$tools.showTx(res.msg)
				}else{
					this.qunDetail.top = eVal?1:2
				}
			},
			delJl(){
				this.popObj = {
					title: "是否确认清空聊天记录!",
					isPop: true,
					isInput: false,
					type: 'delJl'
				}
			},
			sendPopFun(e) {
				console.log(e)
				if(e.type=="delJl"){
					this.delJlFun()
				}
				// this.$tools.showTx(this.$t('common.czcg'))
				this.popObj.isPop = false
			},
			async delJlFun(){
				let url = "api/lt/doDelLog"
				let objData = {
					friend_id: this.id
				}
				if (this.isQun==2) {
					url = "api/qun/doDelQunLog"
					objData = {
						qun_id: this.id,
					}
				}
				const res = await this.$myRequest({
					url: url,
					data: objData
				})
				if (res.code == 1) {
					console.log(res)
					this.$tools.showTx(res.msg)
				}
				
			},
			async getQunUser() {
				const res = await this.$myRequest({
					url: 'api/qun/getQunUser',
					data: {
						qun_id: this.id,
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.qunUser = res.data
				}
			},
			async getQunDetail() {
				const res = await this.$myRequest({
					url: 'api/qun/getQunDetail',
					data: {
						qun_id: this.id,
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.qunDetail = res.data
				}
			},
			onDel(){
				if(this.isQun){
					this.isDel = true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
.set{
	width: 100vw;
	height: 100vh;
	color: #fff;
	.content{
		padding: 0 30rpx;
		.top{
			background: linear-gradient(106deg, rgba(34, 34, 34, 0.6) 0%, rgba(30, 36, 44, 0.39) 100%);
			width: 100%;
			padding: 30rpx 0 30rpx 35rpx;
			display: flex;
			flex-wrap: wrap;
			border-radius: 20rpx;
			.item{
				width: 96rpx;
				margin-right: 35rpx;
				image{
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
					margin-bottom: 10rpx;
				}
				text{
					display: inline-block;
					width: 100%;
					font-size: 24rpx;
					text-align: center;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}
		
		.list{
			margin-top: 30rpx;
			padding: 0 30rpx;
			background: linear-gradient(106deg, rgba(34, 34, 34, 0.6) 0%, rgba(30, 36, 44, 0.39) 100%);
			width: 100%;
			border-radius: 20rpx;
			.list-item{
				height: 96rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				padding: 20rpx 0;
				border-top: 2rpx solid #292929;
				.l{
					
				}
				.r{
					image{
						width: 48rpx;
						vertical-align: middle;
					}
				}
				&:nth-child(1){
					border: none;
				}
			}
			&.del{
				background: #D62629;
				.list-item{
					display: flex;
					justify-content: center;
				}
			}
		}
	}
	
	.pop{
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background-color: rgba(0, 0, 0, .6);
		.content-box{
			width: 100%;
			position: absolute;
			bottom: 0;
			color: #fff;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 90rpx 40rpx;
			background: #000B1B;
			.c{
				margin-top: 50rpx;
			}
			.b{
				width: 100%;
				margin-top: 50rpx;
				display: flex;
				justify-content: space-between;
				.btn{
					width: 300rpx;
					height: 80rpx;
					border-radius: 40rpx;
					border: 2rpx solid #fff;
					display: flex;
					justify-content: center;
					align-items: center;
					&:last-child{
						border: none;
						background: #D62629;
					}
				}
			}
		}
	}
}
</style>

